﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Infragistics.Win.UltraWinDataSource;
using ATA.Data.MisaDAL;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinGrid;

using ATA.Entities;
using ATA.Business;

namespace ATA.Winforms
{
    public partial class frmDangkyATAFastNhaThau : Form
    {
        private Guid gv_khachHangDuThuongID;
        KhachHangDuthuong gv_entKhachhang;
        TList<DoanhSoCamKet> gv_lsDoanhSoCamKet;

        public frmDangkyATAFastNhaThau(string pv_strKhachHangDuThuongID)
        {
            gv_khachHangDuThuongID = new Guid(pv_strKhachHangDuThuongID);

            KhachHangDuthuongService v_srvDuthuong = new KhachHangDuthuongService();
            gv_entKhachhang = v_srvDuthuong.GetById(gv_khachHangDuThuongID);

            InitializeComponent();
            btnCapNhat.Visible = true;
            btnDelete.Visible = true;
            btnThem.Enabled = false;
        }

        public frmDangkyATAFastNhaThau()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void frmDangkyATAFast_Load(object sender, EventArgs e)
        {
            LoadCustomerList();
            LoadBrandList();
            LoadPhanThuongList();
            LoadChuongTrinhList();
            txtMucChietKhauTD.Value = 9;
            cboLoaiSanPham.Value = "ALL";

            if (gv_entKhachhang != null)
            {
                txtSobienban.Value = gv_entKhachhang.SoBienBan;
                dtmNgayKy.Value = gv_entKhachhang.NgayKyBienBan;
                // chuong trinh
                cboChuongtrinhduthuong.Value = gv_entKhachhang.ChuongTrinhId;
                // dai ly
                VwAllCustomersService v_srvAllCustomer = new VwAllCustomersService();
                VList<VwAllCustomers> v_lsCustomers = v_srvAllCustomer.Get("KhachHangID = '" + gv_entKhachhang.HoiVienId.ToString() + "'", "");
                txtCustomers.Value = v_lsCustomers[0].MaKh;
                txtCustomerName.Value = v_lsCustomers[0].TenKh;
                txtCustomers.Enabled = false;
                // thuong hieu
                cboBrandNames.Value = gv_entKhachhang.BrandId;
                // loai san pham
                cboLoaiSanPham.Value = gv_entKhachhang.LoaiSanPham.Trim();
                rdoLoaiThoigian.Value = gv_entKhachhang.Duration;
                dtmStartDate.Value = gv_entKhachhang.StartDate;
                txtMucChietKhauTD.Value = gv_entKhachhang.MucChietKhauTd;
                txtMucChietKhauCC.Value = gv_entKhachhang.MucChietKhauCc;
                cboHienVat.Value = gv_entKhachhang.PhanThuongId;

                LoadDoanhSoCamKet(12);
            }
        }

        private void LoadDoanhSoCamKet(int pv_iDuration)
        {
            if (gv_khachHangDuThuongID == null)
            {
                switch (pv_iDuration)
                {
                    case 1:     // 1 thang
                        dsDoanhso.Rows.Clear();

                        for (int i = 0; i < 1; i++)
                        {
                            UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                            v_grDoanhso["Year"] = (int)(i / 12) + 1;
                            v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                            v_grDoanhso["Month"] = i + 1;
                        }
                        grdDoanhsoCamket.DataSource = dsDoanhso;
                        grdDoanhsoCamket.DataBind();
                        break;
                    case 3:     // 1 quy
                        dsDoanhso.Rows.Clear();

                        for (int i = 0; i < 3; i++)
                        {
                            UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                            v_grDoanhso["Year"] = (int)(i / 12) + 1;
                            v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                            v_grDoanhso["Month"] = i + 1;
                        }
                        grdDoanhsoCamket.DataSource = dsDoanhso;
                        grdDoanhsoCamket.DataBind();
                        break;
                    case 12:     // 1 nam
                        dsDoanhso.Rows.Clear();

                        for (int i = 0; i < 12; i++)
                        {
                            UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                            v_grDoanhso["Year"] = (int)(i / 12) + 1;
                            v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                            v_grDoanhso["Month"] = i + 1;
                        }
                        grdDoanhsoCamket.DataSource = dsDoanhso;
                        grdDoanhsoCamket.DataBind();
                        break;
                    case 36:     // 3 nam
                        dsDoanhso.Rows.Clear();
                        for (int i = 0; i < 36; i++)
                        {
                            UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                            v_grDoanhso["Year"] = (int)(i / 12) + 1;
                            v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                            v_grDoanhso["Month"] = i + 1;
                        }
                        grdDoanhsoCamket.DataSource = dsDoanhso;
                        grdDoanhsoCamket.DataBind();
                        break;
                    default:
                        break;
                }
            }
            else
            {
                DoanhSoCamKetService v_srvDoanhSoCamKet = new DoanhSoCamKetService();
                gv_lsDoanhSoCamKet = v_srvDoanhSoCamKet.Find("KhachHangDuThuongID = '" + gv_khachHangDuThuongID.ToString() + "'");
                grdDoanhsoCamket.DataSource = gv_lsDoanhSoCamKet;
                grdDoanhsoCamket.DataBind();

                grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["KhachHangDuThuongID"].Hidden = true;
                grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["IsActive"].Hidden = true;
            }
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Doanhso"].CellActivation = Activation.AllowEdit;
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Doanhso"].Format = "###,###,##0";
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["DoanhSoLapQuy"].CellActivation = Activation.AllowEdit;
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["DoanhSoLapQuy"].Format = "###,###,##0";
        }

        private void LoadPhanThuongList()
        {
            //ThuongHieuService v_srvThuongHieu = new ThuongHieuService();
            //TList<ThuongHieu> v_lsThuongHieu = v_srvThuongHieu.Find("IsActive = TRUE");
            PhanThuongService v_srvPhanThuong = new PhanThuongService();

            cboHienVat.ValueMember = "ID";
            cboHienVat.DisplayMember = "Name";
            cboHienVat.DataSource = v_srvPhanThuong.Find("IsActive = TRUE");
            cboHienVat.DisplayLayout.Bands[0].Columns["ID"].Hidden = true;
            cboHienVat.DisplayLayout.Bands[0].Columns["Code"].Hidden = true;
            cboHienVat.DisplayLayout.Bands[0].Columns["IsActive"].Hidden = true;
            cboHienVat.DisplayLayout.Bands[0].Columns["Name"].Header.Caption = "Tên phần thưởng";
            cboHienVat.DisplayLayout.Bands[0].Columns["Name"].Width = 200;
            cboHienVat.DisplayLayout.Bands[0].Columns["Value"].Header.Caption = "Giá trị";
            cboHienVat.DisplayLayout.Bands[0].Columns["Value"].Width = 100;
            cboHienVat.DisplayLayout.Bands[0].Columns["Value"].Format = "###,###,###";
            cboHienVat.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;
            cboHienVat.DataBind();
        }

        private void LoadBrandList()
        {

            cboBrandNames.ValueMember = "BrandID";
            cboBrandNames.DisplayMember = "BrandName";
            cboBrandNames.DataSource = Globals.gv_lsThuongHieu;
            cboBrandNames.DataBind();
        }

        private void LoadChuongTrinhList()
        {
            ChuongTrinhService v_srvChuongTrinh = new ChuongTrinhService();
            TList<ChuongTrinh> v_lsChuongTrinh = v_srvChuongTrinh.Find("IsActive = TRUE");

            cboChuongtrinhduthuong.ValueMember = "ChuongTrinhID";
            cboChuongtrinhduthuong.DisplayMember = "TenChuongTrinh";
            cboChuongtrinhduthuong.DataSource = v_lsChuongTrinh;
            cboChuongtrinhduthuong.DataBind();
        }

        private void LoadCustomerList()
        {
            foreach (AccountingObject v_lsParentCusomers in Globals.gv_lsCustomers)
            {
                UltraDataRow row = dsCustomers.Rows.Add();
                row["AccountingObjectId"] = v_lsParentCusomers.AccountingObjectId.ToString();
                row["ParentAccountingObjectId"] = v_lsParentCusomers.ParentAccountingObjectId.ToString();
                row["AccountingObjectName"] = v_lsParentCusomers.AccountingObjectName;
                row["AccountingObjectCode"] = v_lsParentCusomers.AccountingObjectCode;
                foreach (AccountingObject v_lsChildCusomers in Globals.gv_lsCustomersNotInMisa)
                {
                    if (v_lsChildCusomers.ParentAccountingObjectId.Equals(v_lsParentCusomers.AccountingObjectId))
                    {
                        UltraDataRowsCollection childRows = row.GetChildRows("Band 1");
                        UltraDataRow childRow = childRows.Add();
                        childRow["ParentAccountingObjectId"] = v_lsChildCusomers.ParentAccountingObjectId.ToString();
                        childRow["AccountingObjectId"] = v_lsChildCusomers.AccountingObjectId.ToString();
                        childRow["AccountingObjectName"] = v_lsChildCusomers.AccountingObjectName;
                        childRow["AccountingObjectCode"] = v_lsChildCusomers.AccountingObjectCode;
                    }
                }

            }

            grdCustomers.DataSource = dsCustomers;
            grdCustomers.DisplayLayout.Bands[0].Columns["AccountingObjectID"].Hidden = true;
            grdCustomers.DisplayLayout.Bands[0].Columns["ParentAccountingObjectID"].Hidden = true;
            grdCustomers.DisplayLayout.Bands[0].Columns["AccountingObjectCode"].Header.Caption = "Mã KH";
            grdCustomers.DisplayLayout.Bands[0].Columns["AccountingObjectCode"].Width = 120;
            grdCustomers.DisplayLayout.Bands[0].Columns["AccountingObjectName"].Header.Caption = "Tên KH";
            grdCustomers.DisplayLayout.Bands[0].Columns["AccountingObjectName"].Width = 250;
            grdCustomers.DisplayLayout.Bands[1].Columns["AccountingObjectID"].Hidden = true;
            grdCustomers.DisplayLayout.Bands[1].Columns["ParentAccountingObjectID"].Hidden = true;
            grdCustomers.DisplayLayout.Bands[1].Columns["AccountingObjectCode"].Header.Caption = "Mã KH";
            grdCustomers.DisplayLayout.Bands[1].Columns["AccountingObjectCode"].Width = 120;
            grdCustomers.DisplayLayout.Bands[1].Columns["AccountingObjectName"].Header.Caption = "Tên KH";
            grdCustomers.DisplayLayout.Bands[1].Columns["AccountingObjectName"].Width = 250;
            grdCustomers.Width = 520;
            grdCustomers.DataBind();

            DropDownEditorButton objKhachHang = new DropDownEditorButton();
            objKhachHang.Control = this.grdCustomers;
            txtCustomers.ButtonsRight.Add(objKhachHang);
        }

        private void grdCustomers_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs e)
        {
            txtCustomers.Focus();
        }

        private void txtCustomers_AfterEditorButtonCloseUp(object sender, EditorButtonEventArgs e)
        {
            if (grdCustomers.ActiveRow.Index > -1)
            {
                if (grdCustomers.ActiveRow.Cells["AccountingObjectID"].Value != null)
                {
                    txtCustomers.Text = grdCustomers.ActiveRow.Cells["AccountingObjectCode"].Value.ToString();
                    txtCustomerName.Text = grdCustomers.ActiveRow.Cells["AccountingObjectName"].Value.ToString();
                    //LoadDataByCustomer(new Guid(grdCustomers.ActiveRow.Cells["AccountingObjectID"].Value.ToString()));
                }
            }
        }

        private void LoadDataByCustomer(Guid pv_guidCustomerID)
        {
            KhachHangDuthuongService v_srvKhachHangDuThuong = new KhachHangDuthuongService();
            KhachHangDuthuong v_entKhachHangDuThuong = v_srvKhachHangDuThuong.GetByCustomerID(pv_guidCustomerID);

            if (v_entKhachHangDuThuong != null)
            {
                rdoLoaiThoigian.Value = v_entKhachHangDuThuong.Duration;
                dtmStartDate.Value = v_entKhachHangDuThuong.StartDate;
                dtmEndDate.Value = v_entKhachHangDuThuong.EndDate;
                cboBrandNames.Value = v_entKhachHangDuThuong.BrandId;
                cboLoaiSanPham.Value = v_entKhachHangDuThuong.LoaiSanPham;
                txtMucChietKhauTD.Value = v_entKhachHangDuThuong.MucChietKhauTd;
                txtMucChietKhauCC.Value = v_entKhachHangDuThuong.MucChietKhauCc;
                cboChuongtrinhduthuong.Value = v_entKhachHangDuThuong.ChuongTrinhId;

                DoanhSoCamKetService v_srvDoanhSoCamKet = new DoanhSoCamKetService();
                TList<DoanhSoCamKet> v_lsDoanhSoCamKet = v_srvDoanhSoCamKet.GetByCustomerID(v_entKhachHangDuThuong.Id);

                grdDoanhsoCamket.DataSource = v_lsDoanhSoCamKet;
                grdDoanhsoCamket.DataBind();

                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Doanhso"].CellActivation = Activation.AllowEdit;
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Doanhso"].Header.Caption = "Doanh số";
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Year"].Header.Caption = "Năm";
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Quarter"].Header.Caption = "Quý";
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Month"].Header.Caption = "Tháng";
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Month"].Header.Caption = "Tháng";
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["ID"].Hidden = true;
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["KhachHangDuThuongID"].Hidden = true;
                //grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["IsActive"].Hidden = true;
            }
            else
            {
                rdoLoaiThoigian.Value = null;
                dtmStartDate.Value = null;
                dtmEndDate.Value = null;
                cboBrandNames.Value = null;
                cboLoaiSanPham.Value = null;
                txtMucChietKhauTD.Value = null;
                cboChuongtrinhduthuong.Value = null;

                grdDoanhsoCamket.DataSource = null;
                grdDoanhsoCamket.DataBind();
            }
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                KhachHangDuthuongService v_srvDuthuong = new KhachHangDuthuongService();

                gv_entKhachhang.SoBienBan = txtSobienban.Text;
                gv_entKhachhang.NgayKyBienBan = dtmNgayKy.DateTime;

                gv_entKhachhang.BrandId = (int)cboBrandNames.Value;
                gv_entKhachhang.Duration = Convert.ToInt16(rdoLoaiThoigian.Value.ToString());
                gv_entKhachhang.StartDate = new DateTime(dtmStartDate.DateTime.Year, dtmStartDate.DateTime.Month, 1);
                gv_entKhachhang.EndDate = new DateTime(dtmEndDate.DateTime.Year, dtmEndDate.DateTime.Month, 1);
                //gv_entKhachhang.HoiVienId = new Guid(grdCustomers.ActiveRow.Cells["AccountingObjectID"].Value.ToString());
                gv_entKhachhang.ChuongTrinhId = Convert.ToInt16(cboChuongtrinhduthuong.Value);
                gv_entKhachhang.LoaiSanPham = (string)cboLoaiSanPham.Value;
                gv_entKhachhang.MucChietKhauTd = Convert.ToDecimal(txtMucChietKhauTD.Value);
                gv_entKhachhang.MucChietKhauCc = Convert.ToDecimal(txtMucChietKhauCC.Value);
                gv_entKhachhang.PhanThuongId = Convert.ToInt16(cboHienVat.Value);
                gv_entKhachhang.IsActive = true;
                gv_entKhachhang.UpdatedDate = DateTime.Now;

                v_srvDuthuong.Save(gv_entKhachhang);

                DoanhSoCamKetService v_srvDoanhSoCamKet = new DoanhSoCamKetService();
                foreach (UltraGridRow v_rDoanhso in grdDoanhsoCamket.Rows)
                {
                    DoanhSoCamKet v_entDoanhso = v_srvDoanhSoCamKet.GetById(Convert.ToInt16(v_rDoanhso.Cells["ID"].Value));
                    //v_entDoanhso.KhachHangDuThuongId = gv_entKhachhang.Id;
                    v_entDoanhso.Year = Convert.ToInt16(v_rDoanhso.Cells["Year"].Value);
                    v_entDoanhso.Quarter = Convert.ToInt16(v_rDoanhso.Cells["Quarter"].Value);
                    v_entDoanhso.Month = Convert.ToInt16(v_rDoanhso.Cells["Month"].Value);
                    v_entDoanhso.Doanhso = Convert.ToDecimal(v_rDoanhso.Cells["Doanhso"].Value);
                    v_entDoanhso.DoanhSoLapQuy = Convert.ToDecimal(v_rDoanhso.Cells["DoanhSoLapQuy"].Value);
                    v_entDoanhso.IsActive = true;

                    v_srvDoanhSoCamKet.Save(v_entDoanhso);
                }

                MessageBox.Show(this, "Cập nhật thông tin thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Không cập nhật được thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void rdoLoaiThoigian_ValueChanged(object sender, EventArgs e)
        {
            switch (Convert.ToInt16(rdoLoaiThoigian.Value))
            {
                case 1:     // 1 thang
                    dsDoanhso.Rows.Clear();

                    for (int i = 0; i < 1; i++)
                    {
                        UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                        v_grDoanhso["Year"] = (int)(i / 12) + 1;
                        v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                        v_grDoanhso["Month"] = i + 1;
                    }
                    grdDoanhsoCamket.DataSource = dsDoanhso;
                    grdDoanhsoCamket.DataBind();
                    break;
                case 3:     // 1 quy
                    dsDoanhso.Rows.Clear();

                    for (int i = 0; i < 3; i++)
                    {
                        UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                        v_grDoanhso["Year"] = (int)(i / 12) + 1;
                        v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                        v_grDoanhso["Month"] = i + 1;
                    }
                    grdDoanhsoCamket.DataSource = dsDoanhso;
                    grdDoanhsoCamket.DataBind();
                    break;
                case 12:     // 1 nam
                    dsDoanhso.Rows.Clear();

                    for (int i = 0; i < 12; i++)
                    {
                        UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                        v_grDoanhso["Year"] = (int)(i / 12) + 1;
                        v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                        v_grDoanhso["Month"] = i + 1;
                    }
                    grdDoanhsoCamket.DataSource = dsDoanhso;
                    grdDoanhsoCamket.DataBind();
                    break;
                case 36:     // 3 nam
                    dsDoanhso.Rows.Clear();
                    for (int i = 0; i < 36; i++)
                    {
                        UltraDataRow v_grDoanhso = dsDoanhso.Rows.Add();
                        v_grDoanhso["Year"] = (int)(i / 12) + 1;
                        v_grDoanhso["Quarter"] = (int)(i / 3) + 1;
                        v_grDoanhso["Month"] = i + 1;
                    }
                    grdDoanhsoCamket.DataSource = dsDoanhso;
                    grdDoanhsoCamket.DataBind();
                    break;
                default:
                    break;
            }
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Doanhso"].CellActivation = Activation.AllowEdit;
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["Doanhso"].Format = "###,###,##0";
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["DoanhSoLapQuy"].CellActivation = Activation.AllowEdit;
            grdDoanhsoCamket.DisplayLayout.Bands[0].Columns["DoanhSoLapQuy"].Format = "###,###,##0";
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                KhachHangDuthuongService v_srvDuthuong = new KhachHangDuthuongService();
                //KhachHangDuthuong v_entKhachhang = new KhachHangDuthuong();
                KhachHangDuthuong v_entKhachhang;
                v_entKhachhang = new KhachHangDuthuong();
                v_entKhachhang.Id = Guid.NewGuid();

                v_entKhachhang.BrandId = (int)cboBrandNames.Value;
                v_entKhachhang.Duration = Convert.ToInt16(rdoLoaiThoigian.Value.ToString());
                v_entKhachhang.StartDate = new DateTime(dtmStartDate.DateTime.Year, dtmStartDate.DateTime.Month, 1);
                v_entKhachhang.EndDate = new DateTime(dtmEndDate.DateTime.Year, dtmEndDate.DateTime.Month, 1);
                v_entKhachhang.HoiVienId = new Guid(grdCustomers.ActiveRow.Cells["AccountingObjectID"].Value.ToString());
                v_entKhachhang.ChuongTrinhId = Convert.ToInt16(cboChuongtrinhduthuong.Value);
                v_entKhachhang.LoaiSanPham = (string)cboLoaiSanPham.Value;
                v_entKhachhang.MucChietKhauTd = Convert.ToDecimal(txtMucChietKhauTD.Value);
                v_entKhachhang.MucChietKhauCc = Convert.ToDecimal(txtMucChietKhauCC.Value);
                v_entKhachhang.PhanThuongId= (int)cboHienVat.Value;
                v_entKhachhang.IsActive = true;
                v_entKhachhang.UpdatedDate = DateTime.Now;

                v_srvDuthuong.Save(v_entKhachhang);

                DoanhSoCamKetService v_srvDoanhSoCamKet = new DoanhSoCamKetService();
                foreach (UltraGridRow v_rDoanhso in grdDoanhsoCamket.Rows)
                {
                    DoanhSoCamKet v_entDoanhso = new DoanhSoCamKet();
                    v_entDoanhso.KhachHangDuThuongId = v_entKhachhang.Id;
                    v_entDoanhso.Year = Convert.ToInt16(v_rDoanhso.Cells["Year"].Value);
                    v_entDoanhso.Quarter = Convert.ToInt16(v_rDoanhso.Cells["Quarter"].Value);
                    v_entDoanhso.Month = Convert.ToInt16(v_rDoanhso.Cells["Month"].Value);
                    v_entDoanhso.Doanhso = Convert.ToDecimal(v_rDoanhso.Cells["Doanhso"].Value);
                    v_entDoanhso.IsActive = true;

                    v_srvDoanhSoCamKet.Save(v_entDoanhso);
                }

                MessageBox.Show(this, "Cập nhật thông tin thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Không cập nhật được thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                KhachHangDuthuongService v_srvDuthuong = new KhachHangDuthuongService();

                v_srvDuthuong.Delete(gv_entKhachhang);

                DoanhSoCamKetService v_srvDoanhSoCamKet = new DoanhSoCamKetService();

                v_srvDoanhSoCamKet.Delete(gv_lsDoanhSoCamKet);

                MessageBox.Show(this, "Xóa thông tin thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Không cập nhật được thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
